<template>
    <a-menu theme="dark" :inline-collapsed="collapsed" v-model:selectedKeys="selectedKeys" @select="changeRoute" mode="inline">
         <!-- <a-menu-item  v-if="loginId == 'donglee'">
            <template #icon>
                <img src="@/assets/images/icon-3.png" />
            </template>
            <template #title>本地大屏</template>
            <a :href="bigViweUrl2" target="view_window" >
              <span>本地大屏</span>
            </a>
        </a-menu-item> -->
         <a-menu-item  v-if="roleId == 1">
            <template #icon>
               <svg focusable="false" style="color: rgb(70, 135, 255);font-size: 24px;" class="" data-icon="fund" width="1em" height="1em" fill="currentColor" aria-hidden="true" viewBox="64 64 896 896"><path d="M926 164H94c-17.7 0-32 14.3-32 32v640c0 17.7 14.3 32 32 32h832c17.7 0 32-14.3 32-32V196c0-17.7-14.3-32-32-32zm-92.3 194.4l-297 297.2a8.03 8.03 0 01-11.3 0L410.9 541.1 238.4 713.7a8.03 8.03 0 01-11.3 0l-36.8-36.8a8.03 8.03 0 010-11.3l214.9-215c3.1-3.1 8.2-3.1 11.3 0L531 565l254.5-254.6c3.1-3.1 8.2-3.1 11.3 0l36.8 36.8c3.2 3 3.2 8.1.1 11.2z"></path></svg>
            </template>
            <template #title>大屏</template>
            <a :href="bigViweUrl" target="view_window" >
              <span>大屏</span>
            </a>
        </a-menu-item>
        <a-menu-item key="/home" v-if="roleId">
            <template #icon>
                <img src="@/assets/images/icon-1.png" />
            </template>
            <template #title>工作台</template>
            <span>工作台</span>
        </a-menu-item>
        <a-menu-item key="/Management" v-if="roleId">
            <template #icon>
                <img src="@/assets/images/icon-2.png" />
            </template>
            <template #title>单位管理</template>
            <span>单位管理</span>
        </a-menu-item>
        <a-menu-item key="/bugMgmt" v-if="roleId == 1">
            <template #icon>
                <img src="@/assets/images/icon-3.png" />
            </template>
            <template #title>漏洞管理</template>
            <span>漏洞管理</span>
        </a-menu-item>
        <a-menu-item key="/tongbao" >
            <template #icon>
                <img src="@/assets/images/icon-6.png" />
            </template>
            <template #title>通报管理</template>
            <span>通报管理</span>
        </a-menu-item>
        <!-- <a-menu-item key="/inspection" v-if="roleId">
            <template #icon>
                <img src="@/assets/images/icon-4.png" />
            </template>
            <template #title>检验中心</template>
            <span>检验中心</span>
        </a-menu-item> -->
        <a-sub-menu key="sub5" v-if="roleId == 1">
            <template #icon>
                <img src="@/assets/images/icon-5.png" />
            </template>
            <template #title>系统设置</template>
            <a-menu-item key="/Logs">日志管理</a-menu-item>
            <a-menu-item key="/admin">管理员管理</a-menu-item>
            <a-menu-item key="/role">角色管理</a-menu-item>
        </a-sub-menu>
    </a-menu>
</template>

<script>
import { defineComponent } from "vue";
import { Menu } from "ant-design-vue";
export default defineComponent({
    name:"Menu",
    props:{
      collapsed:Boolean,
      routeInfo:Object,
      selected:{
        type:String,
        default:""
      }
    },
    components: {
      AMenu:Menu,
      ASubMenu:Menu.SubMenu,
      AMenuItem:Menu.Item
    },
    data(){
      return {
        loginId:null,
        user:null,
        bigViweUrl:'',
        bigViweUrl2:'',
        roleId:null,//1：分局，2.派出所
        selectedKeys:[],
      }
    },
    watch:{
      selected(newVal){
        if(newVal){
          this.selectedKeys = [newVal];
        }
      }
    },
    mounted(){
      this.selectedKeys = this.selected ? [this.selected] : [];
      if (localStorage.getItem("roleId")) {
        this.roleId = JSON.parse(localStorage.getItem("roleId"));
        const token = localStorage.getItem("token") || null;
        this.bigViweUrl = process.env.VUE_APP_VIEWURL + '?t=' + token;//测试服务地图
        this.bigViweUrl2 = 'http://localhost:8080/?t=' + token;
        this.user = JSON.parse(localStorage.getItem("user"));
        this.loginId = this.user.loginId;
      }else{
        this.$router.push("/login");
      }
      console.log(this.loginId)
    },
    methods:{
      changeRoute(e){
        this.$router.push(e.key);
      }
    }
});
</script>
